package com.ls.herostory.channel.handler;

import com.google.protobuf.GeneratedMessageV3;
import io.netty.channel.Channel;
import io.netty.channel.group.ChannelGroup;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.util.concurrent.GlobalEventExecutor;

/**
 * @author liangsu
 * @version v1.0
 * @Description
 * @Date 2020/10/12 16:12
 * @since
 */
public class BroadCast {

    private static final ChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);

    public static void addChannel(Channel channel){
        channelGroup.add(channel);
    }

    public static void removeChannel(Channel channel){
        channelGroup.remove(channel);
    }

    public static void cast(GeneratedMessageV3 msg){
        channelGroup.writeAndFlush(msg);
    }

}
